package com.mujin.keji.collectionsystem.module.outboundtask.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.dialog.BaseNiceDialog;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.ContactDto;
import com.mujin.keji.collectionsystem.module.outboundtask.views.OneCallActivity;

import java.util.List;


/**
 * 联系人电话
 *
 * @author weishixiong
 * @Time 2018-05-12
 */
public class ConcactAdapter extends RecyclerView.Adapter<ConcactAdapter.ViewHolder> {

    private Context mContext;
    private List<ContactDto> datas;
    private  CallDialogListener listener;
    public interface CallDialogListener {
        void callDialog();
    }

    public ConcactAdapter(Context context, List<ContactDto> datas,CallDialogListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_concat, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvName.setText(datas.get(position).getName());
        holder.tvRelationship.setText(datas.get(position).getRelation());
        holder.tvPhone.setText(datas.get(position).getPhone());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, OneCallActivity.class);
                intent.putExtra("phoneNumber", datas.get(position).getPhone());
                intent.putExtra("caseId",String.valueOf(datas.get(position).getCaseId()));
                intent.putExtra("answering",datas.get(position).getName());
                intent.putExtra("relation",String.valueOf(datas.get(position).getRelation()));
                mContext.startActivity(new Intent(intent));
                listener.callDialog();
            }
        });

    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        private TextView tvPhone;
        private TextView tvPhoneType;
        private TextView tvRelationship;
        private TextView tvName;
        private View itemView;

        public ViewHolder(View itemView) {
            super(itemView);
            this.itemView = itemView;
            tvPhone = (TextView) itemView.findViewById(R.id.tv_phone);
            tvPhoneType = (TextView) itemView.findViewById(R.id.tv_phone_type);
            tvRelationship = (TextView) itemView.findViewById(R.id.tv_relationship);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);


        }

        @Override
        public void onClick(View v) {

        }
    }
}
